package excise;

/**
 * @author CoderXshuai
 */
public class SellTicket implements Runnable {
    private int count;
    private int ID = 5;

    public SellTicket(int count) {
        this.count = count;
    }

    @Override
    public void run() {
        ID = 10;
        while (count > 0) {
            synchronized (this) {
                if (count > 0) {
                    System.out.println("线程" + Thread.currentThread().getName()
                            + "卖出了1张票，余票为=" + count);
                    count--;
                }
            }
            try {
                //线程休眠
                Thread.sleep(1500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }
    }

    public int getID() {
        return ID;
    }

    public void setID(int ID) {
        this.ID = ID;
    }
}